|
|
|
|
|
|
|
example of what an abstract class means. That is, you can't go to the Chrysler dealer and pay for an H-Body car itself. The dealer, instead, will recommend H-Body car classes, such as the Sebring. If you insist on buying the H-Body itself, the puzzled dealer might call a Chrysler plant and tell them that some weirdo wants an H-Body skeleton car. The point is that H-Body is abstract (and might be purely abstract because certain behavior might be implemented at a finer level for certain subclasses). The Sebring class implements the H-Body abstract class. These are entities that are more important to the automotive engineer and repair technician than the buyer (end user). The actual Sebring car is the object that you, the end user, buys. |
|
|
|
|
|
|
|
|
Creating Visual Basic Classes |
|
|
|
|
|
|
|
|
By now, you should be comfortable with the idea of classes and objects and their interrelationships. Let's revisit the Visual Basic development environment where you'll actually create a class and observe simple class behaviors at runtime. |
|
|
|
|
|
|
|
|
There are four ways (also known as development processes) to create classes in Visual Basic. In the Learning, Professional, and Enterprise editions of Visual Basic, you can add a new class module from the standard menu or the right-click pop-up menu or add a new class module that is based on an existing class template in the \Vb\Template folder. In the Enterprise edition, you can use the Class Builder to create a new class or use a modeling tool such as Rational Rose/Visual Basic or Microsoft Visual Modeler. Because these tools are principally for automating the design phase/iteration of the object-oriented software engineering life cycle, they will be discussed in more detail on Day 3, Fundamental Object-Oriented Design. Today you will concentrate on the first three development processes. The following sections familiarize you with the OOP facilities in Visual Basic. |
|
|
|
|
|
|
|
|
By far, the easiest way to add a new class to a Visual Basic project is to add a new class module from the menu. Supporting this menu-driven approach are two implementations of this process. You can either choose Project|Add Class Module from the standard menu at the top of the Visual Basic IDE or right-click in the Project browser on the right side of the Visual Basic IDE. If you use the standard menu approach, you will see a dialog box like the one in Figure 1.2. |
|
|
|
|
|
|
|
|
Double-click the Class Module icon. Visual Basic will add a new class module with the default name Class1 to your project. |
|
|
|
|
|
|
|
|
If you take the right-click pop-up menu approach, you will need to right-click in the Project Browser. A pop-up menu displays. Choose Add Class Module. At this point, you will also see the Add Class Module dialog box (refer to Figure 1.2). Double-click the |
|
|
|
|
|